package com.bodacn.storagescan;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Locale;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    String serviceUrl = "http://192.168.199.186/BDCOMM";
    String serviceUrlExt = "/BDService.asmx?wsdl";
    String curLoginUserNo, curLoginUser, curLoginTime;//操作员所属部门等信息;
    JSONArray curUserPower, funcJsonArray;
    private MainApplication mApp = null;
    GridView grid_func;
    //自身界面需要;
    ImageButton btn_LoginClose;
    TextView txt_titleInv, frameHintText;
    //全局变量
    String STORE_NAME = "Settings";
    String language = "";

    //核心设置的代码
    protected void switchLanguage() {
        //读取配置文件-设置语言
        SharedPreferences settings = getSharedPreferences(STORE_NAME, MODE_PRIVATE);
        serviceUrl = settings.getString("serviceUrl", serviceUrl);
        language = settings.getString("language", language);
        //获取资源
        Resources resources = getResources();
        Configuration config = resources.getConfiguration();
        DisplayMetrics dm = resources.getDisplayMetrics();
        switch (language) {
            case "en":
                config.locale = new Locale("en", "");
                resources.updateConfiguration(config, dm);
                break;
            case "vn":
                config.locale = new Locale("vn", "");
                resources.updateConfiguration(config, dm);
                break;
            default:
                config.locale = new Locale("zh", "");
                resources.updateConfiguration(config, dm);
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //获取登陆参数
        Bundle paramBundle = this.getIntent().getExtras();
        System.out.println(paramBundle);
        curLoginUserNo = paramBundle.getString("LoginUserNo");
        curLoginUser = paramBundle.getString("LoginUser");
        curLoginTime = paramBundle.getString("LoginTime");
        serviceUrl = paramBundle.getString("serviceUrl");
        serviceUrlExt = paramBundle.getString("serviceUrlExt");
        try {
            curUserPower = new JSONArray(paramBundle.getString("UserPower"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        InitView();
        //根据权限加载功能列表
        try {
            funcJsonArray = new JSONArray("[]");
            if (curUserPower != null) {
                if (GetUserFuncPower("FuncInStorageA") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncInStorageA");
                    tmpObject.put("FuncImgName", "in_storagea");
                    tmpObject.put("FuncCaption", "单包入仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncOutStorageA") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncOutStorageA");
                    tmpObject.put("FuncImgName", "out_storagea");
                    tmpObject.put("FuncCaption", "单包出仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncInStorageB") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncInStorageB");
                    tmpObject.put("FuncImgName", "in_storageb");
                    tmpObject.put("FuncCaption", "整单入仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncOutStorageB") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncOutStorageB");
                    tmpObject.put("FuncImgName", "out_storageb");
                    tmpObject.put("FuncCaption", "整单出仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncOutStorageC") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncOutStorageC");
                    tmpObject.put("FuncImgName", "out_cart");
                    tmpObject.put("FuncCaption", "推车出仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncOutStorageD") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncOutStorageD");
                    tmpObject.put("FuncImgName", "out_instruct");
                    tmpObject.put("FuncCaption", "指令单出仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncQueryStorage") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncQueryStorage");
                    tmpObject.put("FuncImgName", "query_storage");
                    tmpObject.put("FuncCaption", "仓库查询");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncStampRec") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncStampRec");
                    tmpObject.put("FuncImgName", "out_cart1");
                    tmpObject.put("FuncCaption", "印花接收");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncEmbroideryRec") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncEmbroideryRec");
                    tmpObject.put("FuncImgName", "embroidery");
                    tmpObject.put("FuncCaption", "绣花接收");
                    funcJsonArray.put(tmpObject);
                }

                if (GetUserFuncPower("CollarInStorage") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "CollarInStorage");
                    tmpObject.put("FuncImgName", "collar");
                    tmpObject.put("FuncCaption", "切领入仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("WorkAgainIn") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "WorkAgainIn");
                    tmpObject.put("FuncImgName", "workagain");
                    tmpObject.put("FuncCaption", "返工入库");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("WorkAgainOut") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "WorkAgainOut");
                    tmpObject.put("FuncImgName", "workagain");
                    tmpObject.put("FuncCaption", "返工出库");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("ProductIn") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "ProductIn");
                    tmpObject.put("FuncImgName", "product");
                    tmpObject.put("FuncCaption", "成品收货");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("ProductOut") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "ProductOut");
                    tmpObject.put("FuncImgName", "product");
                    tmpObject.put("FuncCaption", "成品发货");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("PrintIn") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "PrintIn");
                    tmpObject.put("FuncImgName", "in_instruct");
                    tmpObject.put("FuncCaption", "印花入仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("PrintOut") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "PrintIn");
                    tmpObject.put("FuncImgName", "out_instruct");
                    tmpObject.put("FuncCaption", "印花出仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("TransferRec") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "TransferRec");
                    tmpObject.put("FuncImgName", "transfer");
                    tmpObject.put("FuncCaption", "转移印入仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncTrayBox") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncTrayBox");
                    tmpObject.put("FuncImgName", "out_cart1");
                    tmpObject.put("FuncCaption", "纸箱装托");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncTrayRec") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncTrayRec");
                    tmpObject.put("FuncImgName", "out_cart1");
                    tmpObject.put("FuncCaption", "验针接收");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncBoxTrans") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncBoxTrans");
                    tmpObject.put("FuncImgName", "errortrans");
                    tmpObject.put("FuncCaption", "异常处理");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncBoxTransRec") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncBoxTransRec");
                    tmpObject.put("FuncImgName", "errortrans");
                    tmpObject.put("FuncCaption", "异常接收");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncBcIn") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncBcIn");
                    tmpObject.put("FuncImgName", "in_storageb");
                    tmpObject.put("FuncCaption", "备次入仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncBcOut") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncBcOut");
                    tmpObject.put("FuncImgName", "out_storageb");
                    tmpObject.put("FuncCaption", "备次出仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncHpIn") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncHpIn");
                    tmpObject.put("FuncImgName", "in_storageb");
                    tmpObject.put("FuncCaption", "花片入仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncHpOut") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncHpOut");
                    tmpObject.put("FuncImgName", "out_storageb");
                    tmpObject.put("FuncCaption", "花片出仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncAgvCallBox") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncAgvCallBox");
                    tmpObject.put("FuncImgName", "out_storageb");
                    tmpObject.put("FuncCaption", "呼叫AGV");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncInbox") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncInbox");
                    tmpObject.put("FuncImgName", "inbox");
                    tmpObject.put("FuncCaption", "装箱扫描");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncInStorage") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncInStorage");
                    tmpObject.put("FuncImgName", "instorage");
                    tmpObject.put("FuncCaption", "按箱入库");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncAccBind") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncAccBind");
                    tmpObject.put("FuncImgName", "in_instruct");
                    tmpObject.put("FuncCaption", "辅料绑定");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncAccIn") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncAccIn");
                    tmpObject.put("FuncImgName", "in_instruct");
                    tmpObject.put("FuncCaption", "辅料入仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncAccOut") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncAccOut");
                    tmpObject.put("FuncImgName", "out_instruct");
                    tmpObject.put("FuncCaption", "辅料出仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncFinishOut") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncFinishOut");
                    tmpObject.put("FuncImgName", "out_instruct");
                    tmpObject.put("FuncCaption", "成品箱出仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncNgback") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncNgback");
                    tmpObject.put("FuncImgName", "in_instruct");
                    tmpObject.put("FuncCaption", "NG箱返仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncEmptyAgv") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncEmptyAgv");
                    tmpObject.put("FuncImgName", "out_cart1");
                    tmpObject.put("FuncCaption", "拉走空箱");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncNoSew") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncNoSew");
                    tmpObject.put("FuncImgName", "nosew");
                    tmpObject.put("FuncCaption", "无缝扫描");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncBoxQuery") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncBoxQuery");
                    tmpObject.put("FuncImgName", "query_storage");
                    tmpObject.put("FuncCaption", "箱号查询");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncWanderRec") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncWanderRec");
                    tmpObject.put("FuncImgName", "in_instruct");
                    tmpObject.put("FuncCaption", "托盘流转接收");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncWanderSend") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncWanderSend");
                    tmpObject.put("FuncImgName", "out_instruct");
                    tmpObject.put("FuncCaption", "托盘流转发出");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncWanderFact") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncWanderFact");
                    tmpObject.put("FuncImgName", "in_storageb");
                    tmpObject.put("FuncCaption", "托盘车间接收");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncInstructQuery") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncInstructQuery");
                    tmpObject.put("FuncImgName", "query_storage");
                    tmpObject.put("FuncCaption", "指令单查询");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncEmpQua") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncEmpQua");
                    tmpObject.put("FuncImgName", "nosew");
                    tmpObject.put("FuncCaption", "计件扫描");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncFuliaoIn") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncFuliaoIn");
                    tmpObject.put("FuncImgName", "in_storageb");
                    tmpObject.put("FuncCaption", "辅料入仓");
                    funcJsonArray.put(tmpObject);
                }
                if (GetUserFuncPower("FuncFuliaoOut") == 1) {
                    JSONObject tmpObject = new JSONObject();
                    tmpObject.put("FuncName", "FuncFuliaoOut");
                    tmpObject.put("FuncImgName", "out_storageb");
                    tmpObject.put("FuncCaption", "辅料出仓");
                    funcJsonArray.put(tmpObject);
                }

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }


    @Override
    protected void onResume() {
        super.onResume();
        //显示功能;
        if (funcJsonArray.length() > 0) {
            frameHintText.setVisibility(View.GONE);
            DetailGridAdapter detailGridAdapter = new DetailGridAdapter(this);
            detailGridAdapter.jsonArray = funcJsonArray;
            grid_func.setAdapter(detailGridAdapter);
        }

    }


    //订单表格适配器;
    public final class DetailGridAdapter extends BaseAdapter {
        private LayoutInflater inflater;

        public DetailGridAdapter(Context context) {
            inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        private JSONArray jsonArray;

        @Override
        public int getCount() {
            return jsonArray.length();
        }

        @Override
        public Object getItem(int position) {
            try {
                return jsonArray.get(position);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null)
                convertView = inflater.inflate(R.layout.func_item, null, false);
            String tmpValue;
            try {
                TextView tv = convertView.findViewById(R.id.txt_func);// 显示文字
                if (jsonArray.optJSONObject(position).has("FuncCaption") == true)
                    tv.setText(jsonArray.optJSONObject(position).get("FuncCaption").toString());
                ImageView imv = convertView.findViewById(R.id.img_func);//图标
                if (jsonArray.optJSONObject(position).has("FuncImgName") == true)
                    if (getMipmapResource(jsonArray.optJSONObject(position).get("FuncImgName").toString()) > 0)
                        imv.setImageResource(getMipmapResource(jsonArray.optJSONObject(position).get("FuncImgName").toString()));
            } catch (JSONException e) {
                e.printStackTrace();
                System.out.println(e.getMessage());
            }
            Log.d("msg", "DetailGridAdapter_position:" + position);
            return convertView;
        }

    }

    //获取资源ID
    public int getMipmapResource(String imageName) {
        Context ctx = getBaseContext();
        int resId = getResources().getIdentifier(imageName, "mipmap", ctx.getPackageName());
        //如果没有在"mipmap"下找到imageName,将会返回0
        return resId;
    }

    //获取权限,默认都有;
    private int GetUserFuncPower(String paramFunc) {
        if (curUserPower.length() > 0) {
            for (int i = 0; i < curUserPower.length(); i++) {
                if (curUserPower.optJSONObject(i).has(paramFunc) == true) {
                    try {
                        return curUserPower.optJSONObject(i).getInt(paramFunc);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }
            return 0;
        }
        return 0;
    }

    private void InitView() {
        //全局App;
        mApp = (MainApplication) getApplication();
        //界面变量
        ((TextView) findViewById(R.id.tv_userName)).setText("用户:" + curLoginUser);
        grid_func = findViewById(R.id.grid_func);
        grid_func.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                try {
                    if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncInStorageA") == true) {
                        Func_ScanIn("SingleIn", "单包入仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("CollarInStorageA") == true) {
                        Func_ScanIn("CollarIn", "切领入仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncOutStorageA") == true) {
                        Func_ScanIn("SingleOut", "单包出仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncInStorageB") == true) {
                        Func_ScanIn("WholeIn", "整单入仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncOutStorageB") == true) {
                        Func_ScanIn("WholeOut", "整单出仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncOutStorageC") == true) {
                        Func_ScanIn("CartOut", "推车出仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncOutStorageD") == true) {
                        Func_ScanIn("InstructOut", "指令单出仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncQueryStorage") == true) {
                        Func_Query();
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncStampRec") == true) {
                        Func_Stamp();
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncEmbroideryRec") == true) {
                        Func_Embroidery();
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("CollarInStorage") == true) {
                        Func_ScanIn("CollarInStorage", "切领入仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("TransferRec") == true) {
                        Func_ScanIn("TransferRec", "转移印入仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("WorkAgainIn") == true) {
                        Func_WorkAgain("WorkAgainIn", "返工入仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("WorkAgainOut") == true) {
                        Func_WorkAgain("WorkAgainOut", "返工出仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("ProductIn") == true) {
                        Func_WorkAgain("ProductIn", "成品收货");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("ProductOut") == true) {
                        Func_WorkAgain("ProductOut", "成品发货");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("PrintIn") == true) {
                        Func_Print("PrintIn", "印花入仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("PrintOut") == true) {
                        Func_Print("PrintIn", "印花出仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncTrayBox") == true) {
                        Func_BoxScan("TrayBox", "纸箱装托");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncTrayRec") == true) {
                        Func_BoxScan("TrayRec", "验针接收");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncTrayRec") == true) {
                        Func_BoxScan("TrayRec", "验针接收");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncBoxTrans") == true) {
                        Func_BoxTrans("BoxTrans", "异常处理");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncBoxTransRec") == true) {
                        Func_BoxTrans("BoxTransRec", "异常接收");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncBcIn") == true) {
                        Func_ScanIn("BCIn", "备次入仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncBcOut") == true) {
                        Func_ScanIn("BCOut", "备次出仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncHpIn") == true) {
                        Func_ScanIn("HpIn", "花片入仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncHpOut") == true) {
                        Func_ScanIn("HpOut", "花片出仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncAgvCallBox") == true) {
                        Func_CallAGV("CallBox", "呼叫AGV");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncInbox") == true) {
                        Func_CallAGV("Inbox", "装箱扫描");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncInStorage") == true) {
                        Func_CallAGV("InStorage", "按箱入库");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncInstructSingle") == true) {
                        Func_CallAGV("InstructSingle", "指令单-单包出仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncTransBox") == true) {
                        Func_CallAGV("TransBox", "转箱扫描");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncAccBind") == true) {
                        Func_AccBind("AccBind", "辅料绑定");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncAccIn") == true) {
                        Func_Acc("AccIn", "辅料入仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncAccOut") == true) {
                        Func_Acc("AccOut", "辅料出仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncFinishOut") == true) {
                        Func_FinishOut("FinishOut", "成品箱出仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncNgback") == true) {
                        Func_Ngback("Ngback", "NG箱返仓");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncEmptyAgv") == true) {
                        Func_EmptyAgv("EmptyAgv", "拉走空箱");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncNoSew") == true) {
                        Func_EmptyAgv("NoSew", "无缝扫描");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncBoxQuery") == true) {
                        Func_BoxQuery("BoxQuery", "箱号查询");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncWanderRec") == true) {
                        Func_Wander("WanderRec", "托盘流转接收");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncWanderSend") == true) {
                        Func_Wander("WanderSend", "托盘流转发出");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncWanderFact") == true) {
                        Func_Wander("WanderFact", "托盘车间接收");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncInstructQuery") == true) {
                        Func_InstructQuery("InstructQuery", "指令单查询");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncEmpQua") == true) {
                        Func_EmpQua("EmpQua", "工序报工");
                    } else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncFuliaoIn") == true) {
                        Func_Fuliao("FuliaoIn", "辅料入仓");
                    }else if (funcJsonArray.optJSONObject(i).getString("FuncName").equals("FuncFuliaoOut") == true) {
                        Func_Fuliao("FuliaoOut", "辅料出仓");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
        txt_titleInv = findViewById(R.id.txt_titleInv);
        frameHintText = findViewById(R.id.frameHintText);
        btn_LoginClose = findViewById(R.id.btn_return);
        btn_LoginClose.setOnClickListener(this);


    }

    //调用功能A
    private void Func_EmpQua(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, RecordQuantityActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption);
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }


    //调用功能A
    private void Func_Fuliao(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, FuliaoActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption);
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }



    private void Func_InstructQuery(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, InstructQueryActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption);
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }

    //调用功能A
    private void Func_Wander(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, WanderActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption + "扫描");
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }

    //调用功能A
    private void Func_BoxQuery(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, BoxQueryActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption + "扫描");
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }

    //调用功能A
    private void Func_FinishOut(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, FinishOutActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption + "扫描");
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }

    //调用功能A
    private void Func_EmptyAgv(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, EmptyAgvActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption + "扫描");
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }

    //调用功能A
    private void Func_Ngback(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, NgbackActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption + "扫描");
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }

    //调用功能A
    private void Func_Acc(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, AccScanActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption + "扫描");
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }

    //调用功能A
    private void Func_AccBind(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, AccBoxActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption + "扫描");
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }

    //调用功能A
    private void Func_NoSewBind(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, NoSewActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption + "扫描");
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }

    //调用功能A
    private void Func_CallAGV(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, CallAgvActivity.class);
        if (paramFormType.equals("Inbox"))
            aimerActivity = new Intent(MainActivity.this, InboxActivity.class);
        if (paramFormType.equals("InStorage"))
            aimerActivity = new Intent(MainActivity.this, InstorageActivity.class);
        //if (paramFormType.equals("OutStorage")) aimerActivity=new Intent(MainActivity.this, OutstorageActivity.class);
        //if (paramFormType.equals("InstructWhole")) aimerActivity=new Intent(MainActivity.this, InstructwholeActivity.class);
        if (paramFormType.equals("InstructSingle"))
            aimerActivity = new Intent(MainActivity.this, InstructsingleActivity.class);
        if (paramFormType.equals("TransBox"))
            aimerActivity = new Intent(MainActivity.this, TransboxActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption + "扫描");
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }

    //调用功能A
    private void Func_ScanIn(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, StorageActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption + "扫描");
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }


    //调用功能A
    private void Func_BoxScan(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, BoxActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption + "扫描");
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }

    //调用功能A
    private void Func_BoxTrans(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent aimerActivity = new Intent(MainActivity.this, TransActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption + "扫描");
        aimerActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(aimerActivity);
    }

    //调用功能A
    private void Func_WorkAgain(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent workAgainActivity = new Intent(MainActivity.this, WorkAgainActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption + "扫描");
        workAgainActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(workAgainActivity);
    }

    //调用功能A
    private void Func_Print(String paramFormType, String paramCaption) {
        //跳转前关闭键盘
        Intent workAgainActivity = new Intent(MainActivity.this, PrintActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", paramFormType);
        paramBundle.putString("Caption", paramCaption + "扫描");
        workAgainActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(workAgainActivity);
    }

    //调用功能A
    private void Func_Query() {
        //跳转前关闭键盘
        Intent queryActivity = new Intent(MainActivity.this, QueryActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", "Query");
        paramBundle.putString("Caption", "裁片库存查询");
        queryActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(queryActivity);
    }

    //调用功能A
    private void Func_Embroidery() {
        //跳转前关闭键盘
        Intent tmpActivity = new Intent(MainActivity.this, EmbroideryActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", "Embroidery");
        paramBundle.putString("Caption", "绣花接收扫描");
        tmpActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(tmpActivity);
    }

    //调用功能A
    private void Func_Stamp() {
        //跳转前关闭键盘
        Intent stampActivity = new Intent(MainActivity.this, StampActivity.class);
        //简单参数通过Intent的Extras传递;
        Bundle paramBundle = new Bundle();
        paramBundle.putString("LoginUserNo", curLoginUserNo);
        paramBundle.putString("LoginUser", curLoginUser);
        paramBundle.putString("LoginTime", curLoginTime);
        paramBundle.putString("serviceUrl", serviceUrl);
        paramBundle.putString("serviceUrlExt", serviceUrlExt);
        paramBundle.putString("FormType", "Stamp");
        paramBundle.putString("Caption", "印花接收扫描");
        stampActivity.putExtras(paramBundle);
        //启动主界面;
        startActivity(stampActivity);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_return:
                onBackPressed();

                break;
            default:
                break;
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
